package command

import (
	"fmt"
	"probe/internal/logger"

	"github.com/spf13/cobra"
)

var UninstallCmd = &cobra.Command{
	Use:   "uninstall",
	Short: "uninstall prober service",
	Long:  `uninstall prober service`,
	Run: func(cmd *cobra.Command, args []string) {
		uninstall()
	},
}

func uninstall() error {
	stop()
	err := SRV.Uninstall()
	if err != nil {
		logger.Errorf("Failed to uninstall %v,error:%v\n", Name, err)
		fmt.Printf("Failed to uninstall %v,error:%v\n", Name, err)
		return err
	} else {
		logger.Infof("Succeed to uninstall service %v\n", Name)
		fmt.Printf("Succeed to uninstall service %v\n", Name)
	}
	return nil
}
